package it.xiuxian.personcenter.activity

import android.view.Gravity
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.flyco.tablayout.listener.CustomTabEntity
import it.xiuxian.lib.base.App
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseActivity
import it.xiuxian.lib.bean.TabItem
import it.xiuxian.lib.utils.*
import it.xiuxian.personcenter.R
import it.xiuxian.personcenter.bean.WalletDetailBean
import it.xiuxian.personcenter.databinding.PersoncenterRizhiBinding
import it.xiuxian.personcenter.fragment.RecordFragment
import it.xiuxian.personcenter.presenter.RecordDetailActivityPresenter
import it.xiuxian.swindle.adapter.MyFragmentAdapter
import java.util.*


@Route(path = ArouterAddress.RECORDDETAILACTIVITY)
class RecordDetailActivity:BaseActivity<RecordDetailActivityPresenter>() {
   lateinit var fragments:ArrayList<Fragment>
   lateinit var binding:PersoncenterRizhiBinding
    override val layoutId: Int
        get() = R.layout.personcenter_rizhi
    override val presenter: RecordDetailActivityPresenter
        get() = RecordDetailActivityPresenter()

    override fun initView(){
        fragments = ArrayList()
        binding= getViewDataBinding<PersoncenterRizhiBinding>()
        val titles:Array<String> = arrayOf("贡献值","成长值","我的钱包")
        LiveDataBus.get().with(RxBusCode.RIZHILOADFINISHCODE).observe(this, Observer {
            getCode()
        })
        (binding.cons.layoutParams as LinearLayout.LayoutParams).setMargins(0,
            DensityUtil.getStatusPix(App.INSTANCE.applicationContext)+5,0,0)
        fragments.add(ARouter.getInstance().build(ArouterAddress.RECORDFRAGMENT).withString("flag","1").navigation() as RecordFragment)
        fragments.add(ARouter.getInstance().build(ArouterAddress.RECORDFRAGMENT).withString("flag","2").navigation() as RecordFragment)
        fragments.add(ARouter.getInstance().build(ArouterAddress.RECORDFRAGMENT).withString("flag","3").navigation() as RecordFragment)
        binding.viewpager.adapter= MyFragmentAdapter(supportFragmentManager,fragments)
        binding.viewpager.offscreenPageLimit = 5
        binding.tab.setViewPager(binding.viewpager,titles)
        binding.tab.currentTab = 0
        binding.tab.isTabSpaceEqual = true
        binding.tab.setIndicatorWidthEqualTitle(true)
        binding.tab.textsize = 40f
        binding.tab.setUnderlineGravity(Gravity.BOTTOM)
        binding.tab.indicatorColor =resources.getColor(R.color.red_1)
        binding.tab.textSelectColor = resources.getColor(R.color.red_1)
        binding.tab.textUnselectColor=resources.getColor(R.color.libTextGray)
        binding.tab.setOnTabSelectListener(object : HeySlidingTabLayout.OnTabSelectListener{
            override fun onTabSelect(position: Int): Boolean {
                binding.viewpager.currentItem = position
                return false
            }

            override fun onTabReselect(position: Int) {

            }

        })
        binding.smart.setOnRefreshListener {
           // mPresenter!!.getRecord()
            LiveDataBus.get().with(RxBusCode.RIZHIREFRESHCODE).postValue(1983)
            binding.smart.finishRefresh()
        }
        binding.smart.setOnLoadMoreListener {
            LiveDataBus.get().with(RxBusCode.RIZHILOADMORECODE).postValue(1982)
        }

        binding.cons.setOnClickListener { finish() }
    }

    override fun initData(){
       // mPresenter!!.getRecord()
    }
    fun getCode(){
        binding.smart.finishLoadMore()
    }
    fun setGongXian(data: WalletDetailBean){

    }
}